//
//  JosnToAAndDic.m
//  Air
//
//  Created by dongguozheng on 2016/12/19.
//  Copyright © 2016年 董国政. All rights reserved.
//

#import "JosnToAAndDic.h"

@implementation JosnToAAndDic
- (id)toArrayOrNSDictionary:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSError *error = nil;
    NSData *jsonData=[jsonString dataUsingEncoding:NSUTF8StringEncoding];
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
    
    if (jsonObject != nil && error == nil){
        return jsonObject;
    }else{
        // 解析错误
        return nil;
    }
}
- (id)dictionaryToJson:(NSDictionary *)dic

{
    if (dic) {
        NSError *parseError = nil;
        
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
        
        return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }else
    {
        return nil;
    }
}
-(id)dataToArrDic:(NSData *)data
{
    NSString *josn=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    id ad=[self toArrayOrNSDictionary:josn];
                    return ad;
}

@end
